APP_NAME   := k8soperation
PKG        := ./cmd/server
BIN_DIR    := ./bin
BIN_FILE   := $(BIN_DIR)/$(APP_NAME).exe   # Windows 可执行文件加上 .exe

GO         := go
GOFLAGS    :=
LDFLAGS    := -s -w

.PHONY: all build run clean test fmt lint docker-build docker-run

all: build

build:
	@echo ">> Building $(APP_NAME)"
	@mkdir -p $(BIN_DIR)
	$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BIN_FILE) $(PKG)

run: build
	@echo ">> Running $(APP_NAME)"
	$(BIN_FILE)

test:
	@echo ">> Running tests"
	$(GO) test ./... -v

fmt:
	$(GO) fmt ./...

lint:
	$(GO) vet ./...

clean:
	@echo ">> Cleaning"
	@rm -rf $(BIN_DIR)

docker-build:
	@echo ">> Building Docker image"
	docker build -t $(APP_NAME):latest .

docker-run:
	@echo ">> Running Docker container"
	docker run --rm -p 8080:8080 $(APP_NAME):latest
